<%@ page import="com.xiaolin.dao.impl.UserDAOImpl" %>
<%@ page import="com.xiaolin.utils.dbUtils" %>
<%@ page import="java.sql.Connection" %>
<%@ page import="com.xiaolin.bean.User" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2023/1/4
  Time: 11:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>---处理中---</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
            background-color: green;
        }
        div {
            width: 1920px;
            height: 1080px;
            position: relative;
            color: white;
        }
    </style>
</head>
<body>
<%--<h1>---处理中---</h1>--%>
<div>
    <%
        // login=0登录成功页面，则进行登录，
        String login = request.getParameter("login");
        String password = request.getParameter("password");
        String acNum = request.getParameter("acNum");
        System.out.println(acNum);
        Connection conn = dbUtils.getConnection();
        UserDAOImpl userDAO = new UserDAOImpl();
        out.print("<h1>---处理中---</h1>");
        if (login.equals("0")) {
            User us = userDAO.getUserByAcNum(conn, acNum);
            if (us == null){
                out.print("登录失败，请注册账号或者找回密码！");
                response.setHeader("refresh", "3;url='login.jsp?id=0'");
            }
            String name = us.getName();
            if (us.getPassWord().equals(password)) {
                out.print("登录成功，3秒后转跳到首页！");
                String url = "../index.jsp?name=" + name+"&acNum="+acNum;
                response.setHeader("refresh", "3;url=" + url);
            } else {
                out.print("登录失败，请注册账号或者找回密码！");
                response.setHeader("refresh", "3;url='login.jsp?id=1'");
            }
        } else if (login.equals("1")) {
            //login=1注册成功页面，转跳到登录页面
            //上面已获取账号和密码，这里只需要获取其他的
            String email = request.getParameter("email");
            String name = request.getParameter("name");
            int age = Integer.parseInt(request.getParameter("age"));
            String phone = request.getParameter("phone");
            User us = new User(acNum, password, name, age, email, phone);
            userDAO.insert(conn, us);
            out.println("注册成功，3秒后转跳到登录页面！");
            response.sendRedirect("login.jsp?id=1");
        } else if (login.equals("2")) {
            // login=3则为更改密码页面，更改成功后转跳到登录页面
            String email = request.getParameter("email");
            User us = userDAO.getUserByEmail(conn, email);
            us.setPassWord(password);
            userDAO.update(conn, us);
            response.sendRedirect("login.jsp?id=1");
        }
    %></div>
</body>
</html>
